
const NOW_TIMEMSTAMP = new Date().getTime();
const HOUR_TIMEMSTAMP = 60*60*1000;
const DAY_ONE_TIMEMSTAMP = 24*HOUR_TIMEMSTAMP;
const DAY_TWO_TIMEMSTAMP = 2*DAY_ONE_TIMEMSTAMP;
const DAY_15_TIMEMSTAMP = 15*DAY_ONE_TIMEMSTAMP;
const DEPART_TIME = getDepartTime('2019-07-02 16:53:00');

function getDepartTime(departTime) {
    departTime = departTime.replace(/-/g,'/');
    let timestamp = new Date(departTime).getTime();

    return timestamp;
}
/** 传入当前时间,与发车时间 返回手续费 **/

//let tmpPrice=getRating()*12;


// let roundFun1 = roundFun2(tmpPrice,1);
// console.log(roundFun1)
// 保留小数位,并且小数位向上取整
function roundingMode_UP(value, n) {
    return Math.ceil(value*Math.pow(10,n))/Math.pow(10,n);
}

let ratingObj = {
    refundFlag : true,
    ratingFlag : false,
    rating : 0.00

};

let rating = getRating();
console.log(rating.refundFlag,rating.ratingFlag,rating.rating);

function getRating() {
    let diffTime = DEPART_TIME-NOW_TIMEMSTAMP;

    console.log("当前时间与车票差值: ",diffTime);
    console.log("一小时差值:",HOUR_TIMEMSTAMP);
    console.log("一天差值:",DAY_ONE_TIMEMSTAMP);
    console.log("两天差值:",DAY_TWO_TIMEMSTAMP);
    console.log("15天差值:",DAY_15_TIMEMSTAMP);

    // 判断时差是否大于15天
    if(diffTime>DAY_15_TIMEMSTAMP){
        ratingObj.ratingFlag = false;

        // 大于48小时小于15天
    }else if(DAY_TWO_TIMEMSTAMP<diffTime&&diffTime<=DAY_15_TIMEMSTAMP){
        ratingObj.refundFlag=true;
        ratingObj.ratingFlag=true;
        ratingObj.rating=0.05;

        //大于12小时小于48小时
    }else if(DAY_ONE_TIMEMSTAMP<diffTime&&diffTime<=DAY_TWO_TIMEMSTAMP){
        ratingObj.refundFlag=true;
        ratingObj.ratingFlag=true;
        ratingObj.rating=0.10;

        //大于0小于12小时
    }else if(0<diffTime&&diffTime<=DAY_ONE_TIMEMSTAMP){
        ratingObj.refundFlag=true;
        ratingObj.ratingFlag=true;
        ratingObj.rating=0.20;
    }else{

        //小于当前时间
        ratingObj.refundFlag=false;
    }

    return ratingObj;

}






function run2() {
    console.log("当前时间戳:",NOW_TIMEMSTAMP)
    console.log("一小时后:",HOUR_TIMEMSTAMP+NOW_TIMEMSTAMP);
    console.log("一天后:",DAY_ONE_TIMEMSTAMP+NOW_TIMEMSTAMP);
    console.log("两天后:",DAY_TWO_TIMEMSTAMP+NOW_TIMEMSTAMP);
    console.log("15天后:",DAY_15_TIMEMSTAMP+NOW_TIMEMSTAMP);
}


